import { url } from '../request';

Page({
  data: {
    userName: '请登录',
    userAvatar: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.jHUH4s7TQ48X_B-1iozuJgHaHa?w=207&h=207&c=7&r=0&o=5&dpr=1.5&pid=1.7',
    phone: '无'
  },
  
  onLoad() {},

  godaizhifu() {
    my.navigateTo({
      url: '/pages/daizhifu/daizhifu'
    });
  },
  
  godaiqueren() {
    my.navigateTo({
      url: '/pages/daiqueren/daiqueren'
    });
  },

  godaichuxing() {
    my.navigateTo({
      url: '/pages/daichuxing/daichuxing'
    });
  },

  goyiwancheng() {
    my.navigateTo({
      url: '/pages/yiwancheng/yiwancheng'
    });
  },
  
  goshouhou() {
    my.navigateTo({
      url: '/pages/shouhou/shouhou'
    });
  },
  
  goAllOrders() {
    my.navigateTo({
      url: '/pages/allOrders/allOrders'
    });
  },
  
  goqiandao() {
    my.navigateTo({
      url: '/pages/qiandao/qiandao'
    });
  },
  gomyziliao(){
    my.navigateTo({
      url: "/pages/myziliao/myziliao"
    })
  }
  ,
  denglu() {
    let that = this;
    my.getAuthCode({
      scopes: 'auth_user',
      success: ({ authCode }) => {
        my.request({
          url: url+ "/Alipay/parseCode",
          method: 'GET',
          data: {
            authcode: authCode
          },
          headers: {
            'content-type': 'application/json',
          },
          dataType: 'json',
          success: function (res) {
            my.request({
              url:  url+ "/Alipay/login",
              method: 'GET',
              data: {},
              headers: {
                'content-type': 'application/json',
              },
              success: (res) => {
                if (res.data && res.data.data) {
                  that.setData({
                    userName: res.data.data.account,
                    userAvatar: res.data.data.avatar,
                    phone: res.data.data.phone
                  });
                  my.alert({ title: "登录成功" });
                  my.switchTab({
                    url: '/pages/index/index'
                  });
                }
              }
            });
          }
        });
      }
    });
  }
});
